package com.springsource.boot.run;


import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;
import org.springframework.core.env.SimpleCommandLinePropertySource;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.support.ResourcePropertySource;

import java.io.IOException;

public class Step3 {

    public static void main(String[] args) throws IOException {
        StandardEnvironment standardEnvironment = new StandardEnvironment();
        MutablePropertySources propertySources = standardEnvironment.getPropertySources();
        // 添加外部资源——配置文件（不是本步骤加的）
        propertySources.addLast(new ResourcePropertySource("classpath:config/application.yml"));
        // 添加外部资源——命令行参数
        propertySources.addFirst(new SimpleCommandLinePropertySource(args));
        for (PropertySource<?> propertySource : propertySources) {
            System.out.println(propertySource);
            // PropertiesPropertySource 系统属性，添加在启动参数的VMOptions里 -DKey=Value 优先级较高，先从这里找，这里找不到再从系统环境变量里找
            // SystemEnvironmentPropertySource 系统环境变量
        }
        System.out.println(standardEnvironment.getProperty("name"));
    }


}
